package cn.dxc.demo.controller;

import cn.dxc.demo.common.ResultMapUtil;
import cn.dxc.demo.entity.HeadMenu;
import cn.dxc.demo.service.IHeadMenuService;
import io.swagger.annotations.Api;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "菜单列表")
@RequestMapping("menu")
public class MenuController {

    @Resource
    private IHeadMenuService menuService;

    @GetMapping("/getHead")
    public Object getHeadMenu(){
        try{
            final List<HeadMenu> allHeadMenu = menuService.getAllHeadMenu();

            if (allHeadMenu!=null){
                return ResultMapUtil.getHashMapInfo(allHeadMenu,"1","成功");
            }else {
                return ResultMapUtil.getHashMapInfo(null,"0","失败");
            }

        }catch (DataAccessException e){
            return ResultMapUtil.getHashMapInfo("网络出错了","0","失败");
        }
    }
}
